home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3.2 / Ham Radio Version 3.2 (Chestnut CD-ROMs)(1993).ISO / packet / n17jsrc / makelist.c < prev    next >
C/C++ Source or Header  |  1991-04-20  |  2KB  |  91 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "global.h"
  4.  
  5. static char include[] = "#include";
  6. static char nameline[1024];
  7. static int Recurse = FALSE;
  8. static int Tree = FALSE;
  9.  
  10. void
  11. scanfile( char *filename, int indent )
  12. {
  13.     FILE *fp;
  14.     char buf[512], *name_p, *end_p, *str_p;
  15.  
  16.     fp = fopen(filename,"r");
  17.     if(fp == NULL){
  18.         fprintf(stderr,"Cannot open %s\n",filename);
  19.         return;
  20.     }
  21.  
  22.     while(fgets(buf,512,fp) != NULL){
  23.         if(strncmp(buf,include,sizeof(include)-1) != 0)
  24.             continue;
  25.         if((name_p = strchr(buf,'\"')) == NULL)
  26.             continue;
  27.         name_p++;    /* skip quote */
  28.         if((end_p = strchr(name_p,'\"')) == NULL)
  29.             continue;
  30.         *end_p = '\0';
  31.         if( Tree ){
  32.             int i = 0;
  33.  
  34.             while( i++ < indent )
  35.                 printf("\t");
  36.         }
  37.  
  38.         if( ( str_p = strstr( nameline, name_p ) ) != NULL
  39.          && str_p[-1] == ' ' ){
  40.             if( Tree ){
  41.                 printf( "***\t%s\n", name_p );
  42.             }
  43.         } else {
  44.             if( Tree ){
  45.                 printf( "\t%s\n", name_p );
  46.             }
  47.             strcat( nameline, " " );
  48.             strcat( nameline, name_p );
  49.  
  50.             if( Recurse )
  51.                 scanfile( name_p, indent + 1 );
  52.         }
  53.     }
  54.     fclose(fp);
  55. }
  56.  
  57. main(argc,argv)
  58. int argc;
  59. char *argv[];
  60. {
  61.     char buf[10],*cp;
  62.     int c;
  63.  
  64.     while((c = getopt(argc,argv,"rt")) != EOF){
  65.         switch(c){
  66.         case 't':
  67.             Tree = TRUE;
  68.         case 'r':
  69.             Recurse = TRUE;
  70.             break;
  71.         }
  72.     }
  73.  
  74.     for(;optind<argc;optind++){
  75.         nameline[0] = '\0';
  76.         if( Tree ) {
  77.             printf("%s\n",argv[optind]);
  78.         } else {
  79.             strcpy(buf,argv[optind]);
  80.             if((cp = strchr(buf,'.')) == NULL)
  81.                 continue;
  82.             *cp = '\0';
  83.             printf("%s.obj: %s",buf,argv[optind]);
  84.         }
  85.         scanfile( argv[optind], 0 );
  86.         if( !Tree )
  87.             printf( "%s\n", nameline );
  88.     }
  89.     return 0;
  90. }
  91.